<template>
  <!-- <el-dialog :title="title" :model-value="visible" @update:modelValue="emits('update:visible', $event)"> -->
  <!-- <el-dialog :title="title" :model-value="visible" @close="hide"> -->
  <!-- <el-dialog :title="title" :model-value="getVisible" @close="hide"> -->
  <el-dialog :title="title" :model-value="currentVisible" @close="hide">
    <div class="container">
      <div 
        class="item"
        v-for="(item, index) in Object.keys(Icons)" 
        :key="index"
        @click="clickItem(item)"
      >
        <component :is="`el-icon${toLine(item)}`"></component>
        <div>{{ item }}</div>
      </div>
  </div>
  </el-dialog>
</template>

<script lang='ts' setup>
import { watch, ref, nextTick, computed } from 'vue'
import * as Icons from '@element-plus/icons-vue'
import { toLine } from '../../utils/toLine'
import { useCopy } from '../../hooks/useCopy/useCopy'

console.log('Icons', Icons);

// 复制图标代码
let clickItem = (item: any) => {
  let text = `<el-icon${toLine(item)}/>`
  useCopy(text)
  handleClick()
}

// 方式1
// let props = defineProps<{
//   title: string,
//   visible: boolean
// }>()
// let emits = defineEmits(['update:visible'])

// 方式2
// let props = defineProps<{
//   title: string,
// }>()
// const visible = ref(false)
// const hide = () => {
//   visible.value = false
// }
// const show = () => {
//   visible.value = true
// }
// defineExpose({ show });

// 方式3
// let props = defineProps<{
//   title: string,
//   visible: boolean
// }>()
// let emits = defineEmits(['update:visible'])
// const getVisible = computed({
//   get: () => {
//     return props.visible
//   },
//   set: (val) => {
//     emits('update:visible', val)
//   }
// })
// const hide = () => {
//   getVisible.value = false
// }

// 方式4
let props = defineProps<{
  title: string,
  visible: boolean
}>()
const currentVisible = ref(false)

watch(
  () => props.visible,
  (val) => {
    currentVisible.value = val
  }
)
let emits = defineEmits(['update:visible'])
const hide = () => {
  currentVisible.value = false
  emits('update:visible', currentVisible.value)
}
</script>

<style lang='scss' scoped>
.container {
  display: flex;
  align-items: center;
  justify-content: left;
  flex-wrap: wrap;
}
.item {
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  width: 25%;
  margin-bottom: 20px;
  cursor: pointer;
}
svg {
  width: 2em;
  height: 2em;
}
</style>